// import { Button } from 'antd';
import an58 from '@mmstudio/an000058';
import { message } from 'antd';
import api from '../../../atoms/api';
import { Message as M1, Result as R1 } from '../../api/teachgl/del.api';
import Edit from './edit';
import Add from './add';

// function getWeek(dt: number, base: number) {
// 	const d1 = new Date(Number(dt));
// 	const d2 = new Date(Number(base));
// 	// d2.setMonth(0);
// 	// d2.setDate(1);
// 	const rq = d1.getTime() - d2.getTime();
// 	const days = Math.ceil(rq / (24 * 60 * 60 * 1000));
// 	const num = Math.ceil(days / 7);
// 	return num + 1;
// }

// export default function Section({ data }: { data: ITbcurriculums; }) {
// 	// const trem = await tbtrem().first('*');	// trem 是调用服务获取的
// 	// const start = getWeek(trem.start_time);
// 	const start = 1;
// 	const end = getWeek(new Date('2021/11/2').getTime(), new Date('2021/9/1').getTime());
// 	const arr = new Array<number>(end + 1);
// 	const content = data && `todo: 显示本节课内容
// 			年级：${data.grade},
// 			第${data.startteachingweek}周到第${data.endteachingweek}周`;
// 	return data && <>
// 		<div onContextMenu={(e) => {
// 			// 在这里写鼠标右键事件
// 			e.preventDefault();
// 		}}>
// 			<select>
// 				{arr.fill(0).map((_it, idx) => {
// 					const v = idx + start;
// 					return <option key={v} value={v}>第{v}周</option>;
// 				})}
// 			</select>
// 			{content}
// 		</div>
// 	</>;
// }




export default function Section({ data }: { data: ITbcurriculums; }) {
	console.debug(data);
	if (!data) {
		return <>
			<div>
				<div className='btn' >
					<Add data={undefined} theteacherisqualifiedforthecurriculums={[]} trems={[]} />
				</div>
			</div>
			<style jsx>{`
div .btn{
width: 2rem;
visibility:hidden;
	cursor: pointer;
}
div:hover .btn{
visibility:visible;
}
`}</style>
		</>;
	}
	return <>
		<div className='s01' onContextMenu={(e) => {
			// 在这里写鼠标右键事件
			e.preventDefault();
		}}>
			<div className='box'>
				<div className='btn' >
					<Edit data={undefined} theteacherisqualifiedforthecurriculums={[]} trems={[]} />
				</div>
				<img className='btn' title='删除' onClick={async () => {
					const id = data.course_id;
					const ret = await an58<R1, M1>(api['/api/teachgl/del'], 'delete', {
						id
					});
					if (ret.ok === true) {
						message.success('Success');
						location.reload();
					} else {
						message.error(ret.message);
					}
				}} src='/icons/del.svg'></img>
			</div>
			<div>
				{data.coursename},
				{data.teachername},<br />
				{data.classroom}
				({data.startteachingweek}-{data.endteachingweek})周
			</div>
		</div>
		<style jsx>{`
.box{
	display: flex;
	flex-direction: row;
	position: absolute;
	left: 3rem;
}
.btn{
	width: 1.5rem;
	cursor: pointer;
	margin: 0.5rem;
margin-top: 0rem;
}
.s01 .box {
	display: none;
}
.s01:hover .box {
	display: block;
}
		`}</style>
	</>;
}
